/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tuanzhang.mall.seller.domain.valueobj;

import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;
import com.tuanzhang.mall.seller.types.exception.ApiException;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * 卖家手机号
 *
 * @author wangyl
 */
@Getter
@EqualsAndHashCode(of = "phone")
public class PhoneNumber {

    /**
     * 注册手机号
     */
    private final String phone;

    private PhoneNumber(String phone) {
        if (StrUtil.isBlank(phone)) {
            throw new ApiException("手机号不能为空");
        } else if (!PhoneUtil.isMobile(phone)) {
            throw new ApiException("手机号校验不通过");
        }
        this.phone = phone;
    }


    public static PhoneNumber create(String phone) {
        return new PhoneNumber(phone);
    }

}
